/**
 * @Project Name:cn.hoofungson.studio
 * @Package Name:cn.hoofungson.spring.security.demo.controller
 * @Since JDK 1.8
 */
package cn.hoofungson.spring.security.demo.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;

/**
 * @Description: 用户控制器
 * @Author 胡松 hoofungson@163.com
 * @Date 2017-11-09 14:53
 * @Version V1.0
 */
@Controller
public class UserController {

    @GetMapping("/user")
    @ResponseBody
    public String user(@AuthenticationPrincipal Principal principal, Model model){
        model.addAttribute("username", principal.getName());
        return "user/user";
    }
}
